import {
  UpgradeTaskQueryPageParams,
  UpgradeTaskListResultModel,
  UpgradeTaskCreateItem,
  UpgradeTaskViewParams,
  UpgradeTaskViewItem,
  UpgradeTaskEditItem,
} from './model/upgradeTaskModel';
import { upgradeHttp } from '/@/utils/http/axios';

enum Api {
  UPGRADE_TASK_LIST_PAGE = '/v1/upgrade/getList',
  CREATE_UPGRADE_TASK = '/v1/upgrade/create',
  VIEW_UPGRADE_TASK = '/v1/upgrade/detail',
  EDIT_UPGRADE_TASK = '/v1/upgrade/update',
  ROLLBACK_UPGRADE_TASK = '/v1/upgrade/back',
}

// 根据所选应用 + 企业，分页获取升级任务
export const getUpgradeTasks = (params: UpgradeTaskQueryPageParams) => {
  return upgradeHttp.get<UpgradeTaskListResultModel>({
    url: Api.UPGRADE_TASK_LIST_PAGE,
    params,
  });
};

// 新建升级任务
export const createUpgradeTasks = (params: UpgradeTaskCreateItem) => {
  return upgradeHttp.post<string>({ url: Api.CREATE_UPGRADE_TASK, params });
};

// 查看升级任务详情
export const viewUpgradeTasks = (params: UpgradeTaskViewParams) => {
  return upgradeHttp.get<UpgradeTaskViewItem>({
    url: Api.VIEW_UPGRADE_TASK,
    params,
  });
};

// 编辑升级任务
export const editUpgradeTask = (params: UpgradeTaskEditItem) => {
  return upgradeHttp.post<string>({ url: Api.EDIT_UPGRADE_TASK, params });
};

// 回滚升级任务
export const rollBackUpgradeTask = (params: UpgradeTaskViewParams) => {
  return upgradeHttp.put<string>({
    url: Api.ROLLBACK_UPGRADE_TASK + '/' + params.taskId,
  });
};
